package com.dc.service.impl;

import com.dc.bean.model.BaseModel;
import com.dc.dao.NoticeDao;
import com.dc.dao.impl.NoticeDaoImpl;
import com.dc.service.NoticeService;

import java.util.List;

public class NoticeServiceImpl implements NoticeService {
    NoticeDao noticeDao = new NoticeDaoImpl();
    @Override
    public BaseModel selectNotice(Object[] param) throws Exception {
        BaseModel baseModel = new BaseModel();
        String sql = "select * from t_notice";
        List list = noticeDao.selectNotice(sql);
        baseModel.setCode(1);
        baseModel.setMassage("查询留言成功");
        baseModel.setData(list);
        return baseModel;
    }

    @Override
    public BaseModel delectNotice(String ids) throws Exception {
        BaseModel baseModel = new BaseModel();
        String sql = "delete from t_notice where id in ("+ids+")";
        int result = noticeDao.delectNotice(sql);
        if (result>0){
            baseModel.setCode(1);
            baseModel.setMassage("删除留言成功");
        }else{
            baseModel.setCode(0);
            baseModel.setMassage("删除留言失败");
        }
        return baseModel;
    }

    @Override
    public BaseModel addNotice(Object[] param) throws Exception {
        BaseModel baseModel = new BaseModel();
        String sql = "INSERT INTO t_notice (title,content,time) VALUES (?,?,?)";
        int result = noticeDao.addNotice(sql,param);
        if (result>0){
            baseModel.setCode(1);
            baseModel.setMassage("添加公告成功");
        }else{
            baseModel.setCode(0);
            baseModel.setMassage("添加公告失败");
        }
        return baseModel;
    }
}
